<?php
/*
Template Name: Profilku
*/
?>
<?php if(is_user_logged_in()) 
{ 
		get_header(); 
		global $current_user;
		get_currentuserinfo();
		$user_ID = get_current_user_id(); 
		$showhide = explode("|",esc_attr(get_the_author_meta( 'showhide', $user_ID )));
		//echo esc_attr(get_the_author_meta( 'showhide', $user_ID ));
		$successid = isset( $_GET['success'] ) ? intval( $_GET['success'] ) : 0;
		if ($successid==1){	
		$success = "<span style='color:green'>Data Anda berhasil disimpan!</span>";
		$linkpriview = get_site_url()."/author/".$current_user->user_login;
		}
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {

		$field = array ("TTL","jk","pekerjaan","notelp","email");
	foreach ($field as $fieldlist){
		if (!empty($_POST['cb'.$fieldlist])){
		$showhideedit .= $_POST['cb'.$fieldlist] . "|";
		//$showhideedit .= $fieldlist . "show|";
		}
		else $showhideedit .= $fieldlist ."hide|";
	}
	$showhideedit2 .= rtrim($showhideedit , '|');
	$current_useredit=array(
			'first_name' => $_POST['fnameeditok'],
			'last_name' =>$_POST['lnameeditok'],
			'description' =>$_POST['bioeditok'],
			'pekerjaan' => $_POST['pekerjaaneditok'],
			'ID' => $user_ID
	);
	update_user_meta( $user_ID, 'showhide', $showhideedit2 );
	update_user_meta( $user_ID, 'jk', $_POST['jkeditok'] );
	update_user_meta( $user_ID, 'pekerjaan', $_POST['pekerjaaneditok'] );
	update_user_meta( $user_ID, 'notelp', $_POST['notelpeditok'] );
	update_user_meta( $user_ID, 'tempatlahir', $_POST['tempatlahireditok'] );
	update_user_meta( $user_ID, 'tanggallahir', $_POST['tgllahireditok'] );
	//update_user_meta( $user_ID, 'description', $_POST['bioeditok'] );
	update_user_meta( $user_ID, 'first_name', $_POST['fnameeditok'] );
	update_user_meta( $user_ID, 'last_name', $_POST['lnameeditok'] );

	wp_update_user(	$current_useredit );
	//update_user($user_ID);
	//do_action('')
	wp_redirect(get_site_url()."/profilku?success=1");
}
	?>

	<div class="col-md-12 column content">
	<div class="row clearfix">
	<?php get_template_part('menuprofil');?>
		<div class="col-md-9 column" > <!-- untuk kolom kedua yang dibagi 2 -->
			<div class="row clearfix">
				<div class="col-md-12 column">
                	<div class="box box-primary" style="padding:10px;">
                        <h8 class="judulprofil">Profil Lengkap</h8> <span class='badge'>Score saya : <?php echo get_author_score($current_user->ID);?></span><?php if ($successid==1){ echo '<a href="'.$linkpriview.'"> Klik disini untuk melihat profil baru Anda</a>';}?>
                        <hr class="hr2">
						<?php echo $success;?>
                        <div><form method="post" id="adduser">
                            <div class="list-group-item" style="border-left:none; border-right:none;">
                                <div class="row clearfix">
									<div id="namalengkapdiv">
									<div class="col-md-3">Nama Lengkap (Ditampilkan)</div>
									<div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="lbnamalengkap"><?php echo $current_user->first_name . " " . $current_user->last_name;?></label></div>
									<div class="col-md-2" style="text-align:right"><a id="namalengkap" onclick="ShowEdit(this);"  onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                          onmouseout="this.style.color='Blue';"><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
									</div>
									<div id="namalengkapedit" style="display:none">
									<div class="col-md-3">Nama Depan</div><div class="col-md-8 "><input type="text" name="txtfirstname" id="txtfirstname" placeholder="nama depan" size=40 value="<?php echo $current_user->first_name ?>"/></div><br/>
									<div class="col-md-3">Nama Belakang</div><div class="col-md-8 "><input type="text" name="txtfirstname" id="txtlastname" placeholder="nama belakang" size=40 value="<?php echo $current_user->last_name ?>"/></div>
									<div style="float:right;">
									<a id="namalengkap" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
									<a id="namalengkap" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> </div>
									<label id="errornamalengkap"></label>
									</div>
								</div>
                            </div>
							<div class="list-group-item" style="border-left:none; border-right:none;">
                                <div class="row clearfix">
								<div id="websitediv">
                                <div class="col-md-3">Website (Ditampilkan)</div>
                                <div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id ="awebsite" href="<?php echo $current_user->user_url; ?>"><?php echo $current_user->user_url; ?></a></div>
                                 <div class="col-md-2" style="text-align:right"><a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                                    onmouseout="this.style.color='Blue';" id="website"><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
								</div>
								<div id="websiteedit" style="display:none">
								<div class="col-md-3">Website</div>
								  <div class="col-md-8 "><input id="txtwebsite" type="text" placeholder="website" size=40 value="<?php echo $current_user->user_url; ?>"/></div>
								 <div style="float:right;">
								<a id="website" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
								<a id="website" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								</div>
								</div>
                            </div>
							 <div class="list-group-item" style="border-left:none; border-right:none;">
                                <div class="row clearfix">
								<div id="biodiv">
                                <div class="col-md-3">Bio (Ditampilkan)</div>
                                <div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="lbbio" ><?php echo $current_user->description; ?></a></label></div>
                                <div class="col-md-2" style="text-align:right"><a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                     onmouseout="this.style.color='Blue';" id="bio"><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
								</div>
								<div id="bioedit" style="display:none;">
								 <div class="col-md-3">Bio</div>
								  <div class="col-md-8 "><textarea id="tabio" name="tabio" height="150px" width="300px" placeholder="masukkan bio anda" ><?php echo $current_user->description ?></textarea></div>
								<div style="float:right;">
								<a id="bio" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
								<a id="bio" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								</div>
								</div>
								
                            </div>
                            <div class="list-group-item" style="border-left:none; border-right:none;">
						        <div class="row clearfix">
								<div id="TTLdiv">
                                <div class="col-md-3">Tempat / Tanggal Lahir <label id="ketTTL"><?php if ($showhide[0]=="TTLshow") echo "(Ditampilkan)" ;else echo "(Disembunyikan)";?></label></div>
                                <div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="lbTTL" ><?php echo esc_attr(get_the_author_meta( 'tempatlahir', $user_ID ))?> / <?php echo esc_attr(get_the_author_meta( 'tanggallahir', $user_ID ))?> </label></div>
								<div class="col-md-2" style="text-align:right"><a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                                    onmouseout="this.style.color='Blue';" id="TTL"><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
                                </div>
								<div id="TTLedit" style="display:none">
								<div class="col-md-3">Tempat Lahir</div><div class="col-md-8 "><input type="text" name="txttempatlahir" placeholder="tempat lahir" size=40 id="txttempatlahir" value="<?php echo esc_attr(get_the_author_meta( 'tempatlahir', $user_ID ))?>"/>&nbsp;<input type="checkbox" id="cbTTL" name="cbTTL" value="TTLshow" <?php if ($showhide[0]=="TTLshow") echo 'checked="checked"';?>>&nbspTampilkan</input></div><br/>
								<div class="col-md-3">Tanggal Lahir</div><div class="col-md-8 "><input type="text" name="txttgllahir" placeholder="tanggal lahir" size=40 id="txttgllahir" value="<?php echo esc_attr(get_the_author_meta( 'tanggallahir', $user_ID ))?>" class="date-pick dp-applied"/>
								<a class="dp-choose-date" title="Choose date" href="#">
									Choose date
								</a></div>
								<div style="float:right;">
								<a id="TTL" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
									<a id="TTL" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								
								</div>
								</div>
                            </div>
                            <div class="list-group-item" style="border-left:none; border-right:none;">
								<div class="row clearfix">
								<div id="jkdiv">
                                <div class="col-md-3">Jenis Kelamin <label id="ketjk"><?php if ($showhide[1]=="jkshow") echo "(Ditampilkan)"; else echo "(Disembunyikan)";?></label></div>
								<div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="lbjk"><?php echo esc_attr(get_the_author_meta( 'jk', $user_ID ))?></label></div>
								<div class="col-md-2" style="text-align:right"><a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                     onmouseout="this.style.color='Blue';" id="jk"><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
                                </div>
								<div id="jkedit" style="display:none">
								<div class="col-md-3">Jenis Kelamin </div>
								<div class="col-md-8" id="rdgroup">
								<input type="radio" id="rdperempuan" value="Perempuan" name="rdjk">&nbsp;Perempuan</input> &nbsp;&nbsp;
								<input type="radio" id="rdlaki" value="Laki-laki" name="rdjk">&nbsp;Laki-laki</input>&nbsp;&nbsp;
								<input type="radio" id="rdlainnya" value="Lainnya" name="rdjk">&nbsp;Lainnya</input>
								<label id="errorjk"></label>
								<div><input type="checkbox" id="cbjk" value="jkshow" name="cbjk" <?php if ($showhide[1]=="jkshow") echo 'checked="checked"';?> >Tampilkan</input></div>
								</div>
								<div style="float:right;">
								<a id="jk" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
									<a id="jk" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								</div>
								</div>
                            </div>
							
                            <div class="list-group-item" style="border-left:none; border-right:none;">
                                <div class="row clearfix">
								<div id="pekerjaandiv">
                                <div class="col-md-3">Pekerjaan <label id="ketpekerjaan"></label></div><label id="ketpekerjaan"><?php if ($showhide[2]=="pekerjaanshow") echo "(Ditampilkan)"; else echo "(Disembunyikan)";?></label>
                                <div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="lbpekerjaan"><?php echo esc_attr(get_the_author_meta( 'pekerjaan', $user_ID ))?></label></div>
								<div class="col-md-2" style="text-align:right"><a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                                    onmouseout="this.style.color='Blue';" id="pekerjaan"><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
								</div>
								<div id="pekerjaanedit" style="display:none;">
								<div class="row clearfix" style="padding-left:10px">
								 <div class="col-md-3">Pekerjaan</div>
								  <div class="col-md-8"><textarea width="300px" height="150px" id="txtpekerjaan" placeholder="masukkan pekerjaan anda" type="text">  <?php echo esc_attr(get_the_author_meta( 'pekerjaan', $user_ID ))?></textarea></div><br/>
								</div>
								  <div class="col-md-3 col-md-offset-3"><input type="checkbox" name="cbpekerjaan" id="cbpekerjaan" value="pekerjaanshow" <?php if ($showhide[2]=="pekerjaanshow") echo 'checked="checked"';?>>&nbsp;Tampilkan</input></div>
								<div style="float:right;">
								<a id="pekerjaan" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
									<a id="pekerjaan" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								</div>
                                </div>
                            </div>
                            <div class="list-group-item" style="border-left:none; border-right:none;">
                                <div class="row clearfix">
								<div id="notelpdiv">
                                <div class="col-md-3">No. Telepon <label id="ketnotelp"></label></div><label id="ketnotelp"><?php if ($showhide[3]=="notelpshow") echo "(Ditampilkan)"; else echo "(Disembunyikan)";?></label>
                                <div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="lbnotelp"><?php echo esc_attr(get_the_author_meta( 'notelp', $user_ID ))?><label></div>
								<div class="col-md-2" style="text-align:right"><a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                                   onmouseout="this.style.color='Blue';" id="notelp"><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
								</div>
								<div id="notelpedit" style="display:none;">
								 <div class="col-md-3">No. Telepon</div>
								  <div class="col-md-8 "><input id="txtnotelp" type="text" placeholder="no. telp" size=40  value="<?php echo esc_attr(get_the_author_meta( 'notelp', $user_ID ))?>"></input>&nbsp;<input type="checkbox" id="cbnotelp" name="cbnotelp" value="notelpshow" <?php if ($showhide[3]=="notelpshow") echo 'checked="checked"';?>>&nbsp;Tampilkan</input></div>
								 <div style="float:right;">
								<a id="notelp" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
								<a id="notelp" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								</div>
                                </div>
                            </div>
                            <div class="list-group-item" style="border-left:none; border-right:none;">
                                <div class="row clearfix">
								<div id="emaildiv">
                                <div class="col-md-3">Email <label id="ketemail"><?php if ($showhide[4]=="emailshow") echo "(Ditampilkan)" ;else echo "(Disembunyikan)";?></label></div>
                                <div class="col-md-7 ">:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="lbemail"><?php echo $current_user->user_email;?></label></div>
								<div class="col-md-2" style="text-align:right" ><a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                                   onmouseout="this.style.color='Blue';" id="email" ><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a></div>
								</div>
								<div id="emailedit" style="display:none;">
								<div class="col-md-3">Email</div>
								<div class="col-md-8 "><input id="txtemail" type="text" placeholder="masukkan email" size=40 value="<?php echo $current_user->user_email;?>">&nbsp;<input type="checkbox" name="cbemail" id="cbemail" value="emailshow" <?php if ($showhide[4]=="emailshow") echo 'checked="checked"';?>>&nbsp;Tampilkan</input></div>
								<div style="float:right;">
								<a id="email" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
								<a id="email" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								</div>
                                </div>
                            </div>
							<!-- <div class="list-group-item" style="border-left:none; border-right:none;">
                                <div class="row">
								<div id="passworddiv">
                                <div class="col-md-3">Ubah Password</div><div class="col-md-8"></div>
                               	<div>
								<a onclick="ShowEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"
                                      onmouseout="this.style.color='Blue';" id="password" ><span class="glyphicon glyphicon-edit"></span>&nbsp;&nbsp;Edit</a>
								</div>
								</div>
								<div id="passwordedit" style="display:none;">
								<h9>&nbsp;&nbsp; Ubah Password</h9><hr/>
								<div class="col-md-3">Password lama</div>
								<div class="col-md-8 ">:<input id="txtpwdlama" type="text" /></div>
								<div class="col-md-3">Password baru</div>
								<div class="col-md-8 ">:<input id="txtpwdbaru" type="text" /></div>
								<div style="float:right;">
								<input type="hidden" value="<?php echo $current_user->user_pass;?>" id="pwdlamacurrent"/>
								<label style="font-size:10px;color:red" id="errorpassword"></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<a id="password" onclick="SaveEdit(this);" onmouseover="this.style.cursor='pointer'; this.style.color='Red';"  onmouseout="this.style.color='Black';"><span class="glyphicon glyphicon-ok"></span>Ok</a> &nbsp;&nbsp;
								<a id="password" onclick="HideEdit(this)" onmouseover="this.style.cursor='pointer'; this.style.color='Red';" onmouseout="this.style.color='black';"><span class="glyphicon glyphicon-remove"></span>Batal</a> 
								</div>
								</div>
                                </div>
                            </div> -->
							<input type="hidden" id="fnameeditok" name="fnameeditok" value="<?php echo $current_user->first_name ?>"/>
							<input type="hidden" id="lnameeditok" name="lnameeditok" value="<?php echo $current_user->last_name ?>"/>
							<input type="hidden" id="webisteeditok" name="webisteeditok"value="<?php echo $current_user->user_url; ?>"/>
							<input type="hidden" id="tempatlahireditok"name="tempatlahireditok" value="<?php echo esc_attr(get_the_author_meta( 'tempatlahir', $user_ID ))?>"/>
							<input type="hidden" id="tgllahireditok" name="tgllahireditok" value="<?php echo esc_attr(get_the_author_meta( 'tanggallahir', $user_ID ))?>"/>
							<input type="hidden" id="bioeditok" name="bioeditok" value="<?php echo $current_user->description; ?>"/>
							<input type="hidden" id="pekerjaaneditok" name="pekerjaaneditok" value="<?php echo esc_attr(get_the_author_meta( 'pekerjaan', $user_ID ))?>"/>
							<input type="hidden" id="notelpeditok" name="notelpeditok" value="<?php echo esc_attr(get_the_author_meta( 'notelp', $user_ID ))?>"/>
							<input type="hidden" id="jkeditok" name="jkeditok" value="<?php echo esc_attr(get_the_author_meta( 'jk', $user_ID ))?>"/>
							<input type="hidden" id="emaileditok" name="emaileditok" value="<?php echo $current_user->user_email;?>"/>
							<input type="hidden" id="showhide" name="showhide" value=<?php echo  esc_attr(get_the_author_meta( 'showhide', $user_ID ))?>>
							 <?php 
                      //  action hook for plugin and extra fields
					  
                       
                    ?>
                    
                        <?php// echo $referer; ?>
                        <br/>
						  <button type="submit" class="btn btn-sm" name="submit" >Simpan Perubahan</button>
                        <?php //wp_nonce_field( 'update-user' ) ?>
                        <input name="action" type="hidden" id="action" value="update-user" />
                           </form>
                            <br/>
                                                   
                                    
                        </div>
				
                    </div>
                </div>
            </div>
		</div>
    </div>
	<!-- end untuk content -->
<?php get_footer();?>


</div> <?php }
else { wp_redirect(get_site_url()); }?>
